package com.starblink.brand.adapter

import android.view.View
import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.color
import com.starblink.android.basic.sensorsdata.extension.trackData
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmElementDef
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmPageDef
import com.starblink.basic.style.R
import com.starblink.brand.bean.SortBean
import com.starblink.brand.databinding.ItemBrandSortBinding

class BrandSortCell (binding: ItemBrandSortBinding, val onSelect: ((position: Int) -> Unit)? = null) :
    BaseBindingVH<SortBean, ItemBrandSortBinding>(binding)  {

    val colorNormal = color(R.color.sk_gray500)
    val colorSelect = color(R.color.sk_gray800)


    override fun onBind(model: SortBean, position: Int) {
        binding.tvSortItem.text = model.text
        if (model.select) {
            binding.tvSortItem.setTextColor(colorSelect)
            binding.ivSortItem.visibility= View.VISIBLE
        } else {
            binding.tvSortItem.setTextColor(colorNormal)
            binding.ivSortItem.visibility= View.INVISIBLE
        }
        itemView.trackData(
            page =SpmPageDef.BrandDetailPage,
            element = SpmElementDef.MenuList,
            params = mapOf(
                "sort" to model.text
            ),
            onlyHit=true
        )
        itemView.setOnClickListener {
            onSelect?.invoke(position)
        }
    }
}